package View.Updata;

import Hander.Add.AddProjectViewHandler;
import Hander.Updata.UpdataProjectViewHander2;
import View.LeaderView;
import entity.Project;
import entity.ProjectPersonnelTable;
import service.PersonnelService;
import service.PersonnelServiceImpl;

import javax.swing.*;
import java.awt.*;
import java.util.Vector;

public class UpdataProjectView extends JDialog {
    private String tableName="proj";
    private JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));

    // 添加项目信息
    JLabel projectIDLabel = new JLabel("ProjectID:", JLabel.RIGHT);
    JTextField projectIDTextField = new JTextField();
    JLabel projectNameLabel = new JLabel("ProjectName:", JLabel.RIGHT);
    JTextField projectNameTextField = new JTextField();
    JLabel sourceLabel = new JLabel("Source:", JLabel.RIGHT);
    JTextField sourceTextField = new JTextField();
    JLabel fundingLabel = new JLabel("Funding:", JLabel.RIGHT);
    JTextField fundingTextField = new JTextField();
    JLabel leaderIDLabel = new JLabel("LeaderID:", JLabel.RIGHT);
    JTextField leaderIDTextField = new JTextField();

    JButton addBtn = new JButton("修改");
    UpdataProjectViewHander2 updataProjectViewHander2;

    public UpdataProjectView(LeaderView leaderView, int key) {
        super(leaderView, "修改信息", true);

        PersonnelService personnelService=new PersonnelServiceImpl();
        Vector<Object> array = personnelService.getBy(key, "proj");

//        setTableName(tableName);
        updataProjectViewHander2 = new UpdataProjectViewHander2(this, leaderView);

        projectIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(projectIDLabel);
        projectIDTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(projectIDTextField);
        projectIDTextField.setText(""+array.get(0));

        projectNameLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(projectNameLabel);
        projectNameTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(projectNameTextField);
        projectNameTextField.setText(""+array.get(1));

        sourceLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(sourceLabel);
        sourceTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(sourceTextField);
        sourceTextField.setText(""+array.get(2));


        fundingLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(fundingLabel);
        fundingTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(fundingTextField);
        fundingTextField.setText(""+array.get(3));

        leaderIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(leaderIDLabel);
        leaderIDTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(leaderIDTextField);
        leaderIDTextField.setText(""+array.get(4));

        addBtn.addActionListener(updataProjectViewHander2);
        jPanel.add(addBtn);

        Container contentPane = getContentPane();
        contentPane.add(jPanel);

        setSize(400, 300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);
    }

    public Project buildProject() {
        Project project = new Project();
        project.setProjectID(Integer.valueOf(projectIDTextField.getText()));
        project.setProjectName(projectNameTextField.getText());
        project.setSource(sourceTextField.getText());
        project.setFunding(Double.valueOf(fundingTextField.getText()));
        project.setLeaderID(Integer.valueOf(leaderIDTextField.getText()));
        return project;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
}
